package com.hcb.webservice;

import java.io.File;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import com.hcb.constants.Constants;

public class ServiceHandlerUpload {
	static String responsecontent = null;

	public String uploadService(String pathImg, String _alert_id) {
		DefaultHttpClient httpclient = new DefaultHttpClient();
		HttpPost postRequest = new HttpPost(Constants.URL_SERVICE);
		HttpEntity httpEntity = null;
		try {
			MultipartEntity reqEntity = new MultipartEntity();
			reqEntity.addPart("query", new StringBody("fileTransfer"));
			reqEntity.addPart("alert_id", new StringBody(_alert_id));

			reqEntity.addPart("file_contents", new FileBody(new File(pathImg)));
			reqEntity.addPart("api_secret_key", new StringBody(
					Constants.API_KEY));
			postRequest.setEntity(reqEntity);

			HttpResponse response = httpclient.execute(postRequest);
			httpEntity = response.getEntity();
			responsecontent = EntityUtils.toString(httpEntity);

		} catch (Exception e) {
			// TODO: handle exception
		}
		return responsecontent;
	}
}
